{extend name="template/layout"/}
{block name="main"}
<div class="content">
    <Tabs>
        <tab-pane label="基本信息" name="base">
            <i-form :model="model" :label-width="80">
                <form-item label="用户名" >
                    <i-input type="text" v-model="model.username" clearable placeholder="请输入用户名" />
                </form-item>
            </i-form>
        </tab-pane>
        <tab-pane label="修改密码" name="password">
            <i-form :model="password" :label-width="80">
                <form-item label="原密码" >
                    <i-input type="password" password v-model="password.oldpassword" clearable placeholder="请输入原密码" />
                </form-item>
                <form-item label="新密码" >
                    <i-input type="password" password v-model="password.newpassword" clearable placeholder="请输入新密码" />
                </form-item>
                <form-item label="再次输入新密码" >
                    <i-input type="password" password v-model="password.newpassword2" clearable placeholder="请再次输入新密码" />
                </form-item>
                <i-button :loading="loading" type="primary" style="margin-left: 100px;" @click="onClickChangePassword()">修改密码</i-button>
            </i-form>
        </tab-pane>
    </Tabs>
</div>
{/block}

{block name="script"}
<script>
    function _init() {
        return {
            data: {
                loading: false,
                model: {
                    username: '',
                },
                password: {
                    oldpassword: '',
                    newpassword: '',
                    newpassword2: '',
                }
            },
            mounted() {
                this.initUser()
            },
            methods: {
                initUser: function() {
                    fetch('/admin/index/profile',{}, (res, data) => {
                        if(!res) return
                        this.model.username = data.username
                    })
                },
                onClickChangePassword() {
                    const pwd = 
                    post('/admin/index/changePassword', {
                        oldpassword: btoa(this.password.oldpassword),
                        newpassword: btoa(this.password.newpassword),
                        newpassword2: btoa(this.password.newpassword2),
                    }, (res) => {
                        if(!res) return
                        $Modal.confirm({
                            title: '修改成功',
                            content: '密码修改成功，请重新登录',
                            onOk: () => {
                                window.location.reload(true)
                            }
                        })
                    }) 
                }
            }
        }
    }
</script>
{/block}